﻿using GN.Pay.Core.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Core
{
    /// <summary>
    /// 常量
    /// </summary>
    public static class Consts
    {
        /// <summary>
        /// 启动
        /// </summary>
        public static class Start
        {
            /// <summary>
            /// 启动类型
            /// </summary>
            public static ProcessType ProcessType { get; set; }

            /// <summary>
            /// 启动时间
            /// </summary>
            public static DateTime StartTime { get; set; }

            /// <summary>
            /// 获取消息签名
            /// </summary>
            public static string MessageSign { get; set; }

            private static string _MachineName;

            /// <summary>
            /// 获取计算机名称
            /// </summary>
            public static string MachineName
            {
                get
                {
                    if (string.IsNullOrWhiteSpace(_MachineName))
                    {
                        try
                        {
                            _MachineName = Environment.MachineName;
                        }
                        catch
                        {
                            try
                            {
                                _MachineName = System.Net.Dns.GetHostName();
                            }
                            catch
                            {
                                _MachineName = "Unknown";
                            }
                        }
                    }
                    return _MachineName;
                }
            }

            /// <summary>
            /// 获取本机Ip地址
            /// </summary>
            public static IPAddress Local_IPAddress { get; } = Dns.GetHostAddresses(Dns.GetHostName()).Where(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).First();

        }

        /// <summary>
        /// 本地源名称
        /// </summary>
        public const string LocalizationSourceName = "Pay";

        /// <summary>
        /// 发布信息
        /// </summary>
        public static class ReleaseInfo
        {
            /// <summary>
            /// 文件版本
            /// </summary>
            public const string FileVersion = "0.1.0.2";

            /// <summary>
            /// 程序集版本
            /// </summary>
            public const string AssemblyVersion = "4.5.2.0";

            /// <summary>
            /// 公司名称
            /// </summary>
            public const string Company = "贵州贵农科技有限公司";

            /// <summary>
            /// 商标
            /// </summary>
            public const string Trademark = "GuiNong";

            /// <summary>
            /// 版本
            /// </summary>
            public const string Copyright = "Copyright ©  2015 - 2016";
        }

        /// <summary>
        /// 服务常量
        /// </summary>
        public static class ServiceConstant
        {
            /// <summary>
            /// 账本交易状态
            /// </summary>
            public static class BookTradeState
            {
                /// <summary>
                /// 收款金额小于订单金额
                /// </summary>
                public const int PayMoney_LessThan_OrderMoney = -1;

                /// <summary> 
                /// 收款金额等于订单金额
                /// </summary>
                public const int PayMoney_Equals_OrderMoney = 0;

                /// <summary> 
                /// 收款金额大于订单金额
                /// </summary>
                public const int PayMoney_GreaterThan_OrderMoney = 1;

                /// <summary> 
                /// 收款未知申请
                /// </summary>
                public const int PayMoney_Unknown_Apply = 99;
            }

            /// <summary>
            /// 交易申请状态
            /// </summary>
            public static class TradeApplyState
            {
                /// <summary>
                /// 申请成功
                /// </summary>
                public const int Apply_Success = 1;

                /// <summary>
                /// 申请成功,并正在执行
                /// </summary>
                public const int Executeing = 2;

                /// <summary>
                /// 已执行，并且发生错误
                /// </summary>
                public const int Execute_Error = 3;

                /// <summary>
                /// 已执行，由于账户余额不足造成的错误
                /// </summary>
                public const int Execute_Balance_Error = 4;

                /// <summary>
                /// 已执行，但信息出错，不可能成功
                /// </summary>
                public const int Execute_Info_Error = 50;

                /// <summary>
                /// 执行成功
                /// </summary>
                public const int Execute_Success = 100;
            }

            /// <summary>
            /// 交易通知类型
            /// </summary>
            public static class TradeNotifyType
            {
                /// <summary>
                /// 付款
                /// </summary>
                public const int Pay = 1;

                /// <summary>
                /// 退款
                /// </summary>
                public const int Refund = 2;

                /// <summary>
                /// 转账
                /// </summary>
                public const int Transfers = 3;
            }
        }

        /// <summary>
        /// 任务常量
        /// </summary>
        public static class TaskConstant
        {
            /// <summary>
            /// 工作任务类型
            /// </summary>
            public static class TaskMonitorType
            {
                /// <summary>
                /// 通知错误队列类型
                /// </summary>
                public static int NotifyErrorQueueType { get; } = 1001;
                
            }
        }
    }


}
